﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Framework;

namespace TjZheng.DataStructure.Program
{
    /// <summary>
    /// 冒泡排序
    /// </summary>
    public class BubbleSort : IExecuteResult
    {
        public void Execute()
        {
            int[] array = new int[] { 6, 3, 7, 2, 9, 0, 5, 1, 8, 4 };
            int a = 0;
            bool change = true;
            for (int i = 0; i < array.Length - 1 & change; i++)
            {
                change = false;
                for (int j = 0; j < array.Length - i - 1; j++)
                {
                    if (array[j] > array[j + 1])
                    {
                        a = array[j];
                        array[j] = array[j + 1];
                        array[j + 1] = a;
                        change = true;
                    }
                }
                Console.WriteLine(array.JoinComma());
            }
            //for (int i = 0; i < array.Length; i++)
            //{
            //    Console.WriteLine(array[i]);
            //}
        }
    }
}
